package hg.demo.mybatis.plus.controller;

import hg.demo.mybatis.plus.entity.UserEntity;
import hg.demo.mybatis.plus.service.UserService;
import hg.framework.common.controller.BaseController;
import hg.framework.common.controller.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/user")
@RestController
public class UserController extends BaseController {

    @Autowired
    private UserService hgUserService;

    @RequestMapping(value = "/query/{name}")
    public R<UserEntity> query(@PathVariable("name") String name) {
        R result = new R();
        UserEntity userEntity = hgUserService.query(name);
        if (null == userEntity) {
            result.failed("用户不存在");
        } else {
            result.ok(userEntity);
        }
        return result;
    }
}
